package com.gxa.controller.HospitalController;

import com.gxa.entity.Campus;
import com.gxa.service.NavigationService;
import com.gxa.utils.R;
import com.gxa.vo.NavigationVo;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;


@Api(tags = "医院导航相关接口")
@RestController
public class NavigationController {

    @Autowired
    private NavigationService navigationService;

    Campus campus = new Campus();

    @ApiOperation(value="查询接口",notes="方法的详细描述",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回查询详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 400, message = "请求错误"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("hos:sel")
    @PostMapping("/doc/QueryNavigation")
    public R QueryNavigation(@ApiParam(name="院区名",value = "根据院区名查询",required = true)@RequestBody NavigationVo navigationVo){

        List<NavigationVo> navigationVos = this.navigationService.queryNaviByName(navigationVo.getCampus());
        return R.ok().put("data",navigationVos);

    }
    @ApiOperation(value="修改前查询接口",notes="查询联系电话1、公交",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回查询详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 400, message = "请求错误"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("hos:sel")
    @PostMapping("/doc/PreEditNavigation")
    public R PreEditNavigation(@ApiParam(name="院区名",value = "根据院区名查询",required = true)@RequestBody NavigationVo navigationVo){

        int id = this.navigationService.queryNavigationId(navigationVo.getCampus());
        this.campus.setId(id);
        List<NavigationVo> navigationVos1 = this.navigationService.queryNaviByName1(navigationVo.getCampus());
        System.out.println(navigationVos1);
        return R.ok().put("data",navigationVos1);

    }

    @ApiOperation(value="修改接口",notes="方法的详细描述",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回查询详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 400, message = "请求错误"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("hos:update")
    @PutMapping("/doc/EditNavigationVo")
    public R EditNavigationVo(@ApiParam(name="修改后的数据",value = "根据修改后的数据修改",required = true)@RequestBody NavigationVo navigationVo){
        this.campus.setName(navigationVo.getCampus());
        this.campus.setAddress(navigationVo.getAddress());
        this.campus.setBus(navigationVo.getBus());
        this.campus.setPhone1(navigationVo.getPhone1());
        this.campus.setPhone2(navigationVo.getPhone2());
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
        campus.setTime(sdf.format(new Date()));
        this.navigationService.updateNavigation(campus);
        System.out.println(campus);
        System.out.println(navigationVo);
        return R.ok();
    }



    @ApiOperation(value="添加接口",notes="添加",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回查询详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 400, message = "请求错误"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("hos:add")
    @PostMapping("/doc/addNavigation")
    public R addNavigation(@ApiParam(name="添加内容",value = "添加内容",required = true)@RequestBody NavigationVo navigationVo){

        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
        navigationVo.setTime(sdf.format(new Date()));
        this.navigationService.insertNavigation(navigationVo);

        System.out.println(navigationVo);
        return R.ok();

    }

    @ApiOperation(value="删除接口",notes="删除",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回查询详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 400, message = "请求错误"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("hos:del")
    @DeleteMapping("/doc/DelNavigation")
    public R DelNavigation(@ApiParam(name="删除",value = "删除",required = true)@RequestBody NavigationVo navigationVo){
        this.navigationService.deleteNavigation(navigationVo.getCampus());

        System.out.println(navigationVo);
        return R.ok();

    }

    @ApiOperation(value="无参查询接口",notes="方法的详细描述",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回查询详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 400, message = "请求错误"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("hos:sel")
    @PostMapping("/doc/QueryNavigat")
    public R QueryNavigat(){

        List<NavigationVo> navigationVos = this.navigationService.queryNavigations();
        return R.ok().put("data",navigationVos);
    }
}
